require(['./config'],()=>{
	require(['template','header','footer'],()=>{
		class Register{
			constructor() {
			    this.SignIn()
				this.keep()
				this.checkform()
			}
			SignIn(){
				
				$('#registerbtn').on('click',()=>{
					this.userinfo={
							name:$('#userid').val(),
							password:$('#userpassword').val()
						}
					console.log(this.userinfo)					
					const checkstat=$('#conset').prop('checked')
					if(checkstat){
						
						//获取localstorage里面是否有数据
						let userList=localStorage.getItem('userList')
						if(userList){
							//已经注册了其他用户
							//取出来的字符串解析为数组
							userList=JSON.parse(userList)
							//把现在的push进去
							userList.push(this.userinfo)
							localStorage.setItem('userList',JSON.stringify(userList))
							alert('恭喜你注册成功，即将跳转到登录页面')
							location.href='/html/login.html'
						}else{
							localStorage.setItem('userList',JSON.stringify([this.userinfo]))
						}
					}else{
						alert('同意协议才能注册')
					}
				})
				
				
			}
			checkform(){	
				 $("#userid").blur(function(){
				            if(($(this).val())==''){
				                $("#userid_msg").html("用户名不能为空");
				            }else{
				                var $reg=/^\w{6,}$/;
				                if(!$reg.test($("#password").val())){
				                    $("#userid_msg").html("密码至少要6位哦");
				                }else{
				                    $("#userid_msg").html("√");
				                }
				            }
				        });
			}
			keep(){
				// localStorage.setItem('user',{this.userinfo},resp=>{
				// 	console.log(1)
				// })
			}
		}
		new Register()
	})
})